<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2025/2/24
 * Time: 10:59
 */

namespace app\common\service;


use app\common\enum\Adminuser_typeEnum;
use app\common\enum\EtcOfficeProductSelected_SendStatusEnum;
use app\models\EtcOfficeProductSelected;
use app\models\EtcOfficeVideoUpload;
use app\models\EtcSellerTiktokShop;
use app\modules\setting\models\auth\SetAuthYhzx;
use app\modules\setting\models\seller\SetSellerYhzx;
use sookie\auth\models\Adminuser;

class SystemCount
{
    public static function count(){
        /**
         * @var $model SetAuthYhzx
         */
        $model = SetAuthYhzx::findOne();
        $model['office_num'] = Adminuser::find()->andWhere(['type'=>Adminuser_typeEnum::OFFICE])->count();
        $model['seller_num']= Adminuser::find()->andWhere(['type'=>Adminuser_typeEnum::SELLER])->count();
        $model['store_num'] = EtcSellerTiktokShop::find()->count();
        $model['selling_product'] = EtcOfficeProductSelected::find()->count();
        $model['video_num'] = EtcOfficeVideoUpload::find()->count();
        $model['tiktok_num'] = EtcOfficeVideoUpload::find()->count("distinct tiktok_id");
        $model->save();


        $info = Adminuser::getUserInfo();

        /**
         * @var $model_seller SetSellerYhzx
         */
        $model_seller = SetSellerYhzx::findOne();
        $model_seller->selected_num =  EtcOfficeProductSelected::find()->andWhere(['seller_id'=>$info->id])->count();
        $model_seller->wait_send_num =  EtcOfficeProductSelected::find()->andWhere(['seller_id'=>$info->id,'send_status'=>EtcOfficeProductSelected_SendStatusEnum::NO])->count();
        $model_seller->selling_num =  EtcOfficeProductSelected::find()->andWhere(['seller_id'=>$info->id,'send_status'=>EtcOfficeProductSelected_SendStatusEnum::SIGN])->count();
        $model_seller->save();
    }
}